import { get, post, put, del } from '@/utils/http'
import { BaseResponse, GetTasksResponse, GetTaskDetail } from '@/api/modules/taskModels'

const apiList = {
    add_task: "/notes/",
    get_tasks: "/notes/",
    update_task: (id: string | number) => `/notes/${id}`,
    delete_task: (id: string | number) => `/notes/${id}`,
    get_task_detail: (id: string | number) => `/notes/${id}`
}

export const addTaskAPI = async (data: object): Promise<BaseResponse> => {
    return await post<BaseResponse>(apiList.add_task, data)
}

export const getTasksAPI = async (params: object): Promise<GetTasksResponse> => {
    return await get<GetTasksResponse>(apiList.get_tasks, params)
}

export const updateTaskAPI = async (id: number, data: object): Promise<BaseResponse> => {
    return await put<BaseResponse>(apiList.update_task(id), data)
}

export const deleteTaskAPI = async (id: number): Promise<BaseResponse> => {
    return await del<BaseResponse>(apiList.delete_task(id))
}

export const getTaskDetailAPI = async (id: number): Promise<GetTaskDetail> => {
    return await get<GetTaskDetail>(apiList.get_task_detail(id), {})
}